package com.capsulode.excel.sheetreader;


import com.capsulode.excel.BatchConsumer;
import com.capsulode.excel.domain.ExcelImportResult;
import org.apache.poi.ss.usermodel.Sheet;

/**
 * Read `Excel WorkSheet` and collect failures.
 *
 * @param <R> type of row wrapper object.
 */
public interface SheetReader<R> {

    /**
     * Set the batch size of rows to consume.
     * If `Sheet` row size is greater then batch size, rows will been batched to {@link #consume(Sheet, BatchConsumer) consume}.
     *
     * @param size the batch size
     * @return this SheetReader for chain operation.
     */
    SheetReader<R> batchSize(int size);

    /**
     * Explicitly specify the row index where data begin.
     * @param rowIndex a positive number or `-1` means guessing by SheetReader.
     * @return this SheetReader for chain operation.
     */
    SheetReader<R> from(int rowIndex);

    /**
     * Consume the batched rows.
     *
     * @param sheet Excel WorkSheet
     * @param batch consumer
     * @return A result contains some failures which been ignored by importing process.
     */
    ExcelImportResult consume(Sheet sheet, BatchConsumer<R> batch);
}
